/*
2020年6月12日较为成熟的
node服务器
程序
*/
var http = require('http')
var fs = require('fs')
http
    .createServer(function (request,response) {
        var url = request.url
        var web_data = ''
        response.setHeader('Content-Type','text/html;charset=utf-8')
        if (url === '/') {
            fs.readFile('./www/index.html',function (err,data) {
                if (err){
                    web_data = 'not to found'
                    return response.end(web_data)
                }else {
                    web_data = data.toString()
                    return response.end(web_data)
                }
            })
        }/*else if (url.indexOf('/www/') === 0) {
            fs.readFile('.'+url,function(err,data) {
                if (err) {
                    web_data = 'not to found the url'
                    return response.end(web_data)
                }else {
                    web_data = data.toString()
                    return response.end(web_data)
                }
            })
        }*/else {
            response.end('请求不合法')
        }
        console.log(request.socket.remoteAddress+request.socket.remotePort)
    }).listen(80,function () {
        console.log('server is running.....')
    })